package jgo.plugins;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jgo.Http;
import jgo.JGo;
import jgo.RouterPlugin;
import jgo.core.ServerPlugin;
import jgo.plugins.server.SimpleServerPlugin;

public class StartupTimePlugin extends ServerPlugin {
	private static final Logger logger = LoggerFactory.getLogger(StartupTimePlugin.class);
	private long startTime;

	@Override
	public void init(JGo jgo) {
		startTime = System.nanoTime();
		logger.info("开始记录服务器启动时间");
	}

	@Override
	public void start(JGo jgo) {
		long endTime = System.nanoTime();
		long duration = endTime - startTime;
		logger.info("服务器启动耗时: {} 毫秒", duration/1000);
	}

	// 移除 main 方法

	public static void main(String[] args) {
		JGo g = new JGo();
		g.use(new StartupTimePlugin());
		g.use(new SimpleServerPlugin());
		g.use(new RouterPlugin().addRoute(Http.GET, "/", (ctx) -> {

			ctx.string("OK");

		}));
		g.run();
		

	}

}